//
// $Id$

package com.samskievert.cactusboom;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

 import com.samskivert.swing.MultiLineLabel;
 import com.threerings.toybox.client.ToyBoxUI;

 import java.awt.Polygon;
 import java.awt.geom.Ellipse2D;
 import javax.swing.Icon;
 import com.samskivert.swing.ShapeIcon;
 import com.threerings.parlor.turn.client.TurnDisplay;


import com.samskivert.swing.GroupLayout;

import com.threerings.crowd.client.PlacePanel;
import com.threerings.util.MessageBundle;

import com.threerings.toybox.client.ChatPanel;
import com.threerings.toybox.util.ToyBoxContext;

import java.awt.image.BufferedImage;


/**
 * Contains the primary client interface for the game.
 */
public class CBPanel extends PlacePanel
{
    /**
     * Creates a Reversi panel and its associated interface components.
     */
     
    private BufferedImage _bgTile;
    private BufferedImage _bgCorner;
    
    public CBPanel (ToyBoxContext _ctx, CBController ctrl)
    {
    
        super(ctrl);
        ctx = _ctx;

        // this is used to look up localized strings
        MessageBundle msgs = _ctx.getMessageManager().getBundle("cactusboom");

        

        // construct the background panel
        bgPanel back = new bgPanel(_ctx);
        back.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        back.setLayout(new BorderLayout());
        

        /*
        // give ourselves a wee bit of a border
	setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setLayout(new BorderLayout());
      
        // give ourself a soothing yellow background
        setBackground(new Color(252,236,202));
        
        */
        

        // create and add our board view
        // create a container that will hold our board/buttons view in its center
        JPanel box = GroupLayout.makeVBox();
        
        boardContainer = GroupLayout.makeVBox();
        // create our territory view and the puzzle view
        tview = new CBTerritoryView(ctx, ctrl);
        bview = new CBBoardView(ctx, ctrl);
        boardContainer.add(tview);
        boardContainer.add(bview);
        //boardContainer.setBackground(new Color(252,236,202));
        box.add(boardContainer);
        
        //JButton pass = CBController.createActionButton("Pass","passTurn");
        //box.add(pass,GroupLayout.FIXED);
        box.setOpaque(false);
        
        /*
        JPanel buttons = GroupLayout.makeHBox();
        box.add(buttons, GroupLayout.FIXED);  
         */
        
        back.add(box, BorderLayout.CENTER);
        
        /*
        //now do the same for the score view
        JPanel box2 = GroupLayout.makeVBox();
        // create and add our board view
        box2.add(sview = new CBScoreView(ctx, ctrl));
        box2.setOpaque(false);
        add(box2, BorderLayout.SOUTH);
        */
        
        // create a side panel to hold our chat and other extra interfaces
        JPanel sidePanel = GroupLayout.makeVStretchBox(10);
        //sidePanel.setBackground(new Color(252,236,202));
        
        // add a big fat label
        MultiLineLabel vlabel = new MultiLineLabel(msgs.get("m.title"));
        vlabel.setAntiAliased(true);
        vlabel.setFont(ToyBoxUI.fancyFont);
        vlabel.setForeground(Color.WHITE);
        vlabel.setBackground(new Color(255,255,255,0));
        vlabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        
        sidePanel.setBackground(new Color(255,255,255,0));
        sidePanel.add(vlabel, GroupLayout.FIXED);
        
        
        
        //JPanel lowerPanel = GroupLayout.makeVStretchBox(0);
        //sidePanel.setBackground(new Color(252,236,202));
        sidePanel.add(sview = new CBScoreView(ctx, ctrl,tview));
       
        // add a chat box
        ChatPanel chat = new ChatPanel(ctx);
        chat.setBackground(new Color(252,236,202));
        sidePanel.add(chat);

        // add a "back to lobby" button
        JButton backLobby = CBController.createActionButton(
            msgs.get("m.back_to_lobby"), "backToLobby");
        sidePanel.add(backLobby, GroupLayout.FIXED);

        // add our side panel to the main display
        back.add(sidePanel, BorderLayout.EAST);
        
        setLayout(new BorderLayout());
        add(back,BorderLayout.CENTER);
    }
    
    public void enableCursor(){
        tview.enableCursor();
        bview.enableCursor();
    }

    /** Provides access to various client services. */
    public ToyBoxContext ctx;

    //so we can swap the views in and out
    public JPanel boardContainer;
            
    /** The puzzle game view. */
    public CBBoardView bview;

    /** The board game view. */
    public CBTerritoryView tview;
        
    /** The score view. */
    public CBScoreView sview;
}
